package com.xopencode.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Auther: Mcb
 * @Date: 2022/3/1 22:18
 * @Description: 资源加载,加载本地资源或者网络资源
 */

public class ResourceLoad {


    public static void main(String[] args) throws IOException {

        ApplicationContext applicationContext = new AnnotationConfigApplicationContext();

        //本地资源
        Resource resource = applicationContext.getResource("file://D:\\idea\\Storage\\src\\main\\resources\\resoueces");
        System.out.println("资源长度："+resource.contentLength());
        System.out.println(resource.getURI());
        System.out.println(resource.getURL());

        Resource javaResource = applicationContext.getResource("file://D:\\idea\\Storage\\src\\main\\java\\com\\xopencode\\StringDemo\\StringUtil.java");
        System.out.println("java文件："+javaResource.contentLength());


        //网络资源
        Resource baidu = applicationContext.getResource("https://www.baidu.com");
        System.out.println(baidu.getURL());
    }

}
